﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChatApp.Core.Business;
using ChatApp.Core.Info;

namespace ChatApp.Core.Facade
{
    public class UserFacade : IUserFacade
    {
        IUserBusiness aUserBusiness = new UserBusiness();
        IRoleBusiness aRoleBusiness = new RoleBusiness();
        IUserRoleBusiness aUserRoleBusiness = new UserRoleBusiness();
        public IList<UserInfo> getAlluser()
        {
            return aUserBusiness.SelectAll();
        }

        public UserInfo Authenticate(string UserName, string Password)
        {
            var lParameterInfo = new List<ParameterInfo>();
            lParameterInfo.Add(new ParameterInfo() { Name = "UserName", Value = UserName });
            lParameterInfo.Add(new ParameterInfo() { Name = "Password", Value = Password });
            var aUserInfo = aUserBusiness.SelectByParams(lParameterInfo).FirstOrDefault();
            return aUserInfo;
        }

        public UserInfo getUser(string UserName)
        {
            var lParameterInfo = new List<ParameterInfo>();
            lParameterInfo.Add(new ParameterInfo() { Name = "UserName", Value = UserName });
            return aUserBusiness.SelectByParams(lParameterInfo).FirstOrDefault();
        }

        public IList<UserInfo> GetUserSystemManager(string RoleName)
        {
            //var aParameterInfo = new List<ParameterInfo>();
            //aParameterInfo.Add(new ParameterInfo() {Name = "RoleName", Value = "system"});
            //var aRoleInfo = aRoleBusiness.SelectByParams(aParameterInfo).FirstOrDefault();
            //if (aRoleInfo != null)
            //{
            //    aParameterInfo.Clear();
            //    aParameterInfo.Add(new ParameterInfo(){Name = "RoleId", Value = aRoleInfo.RoleId});
            //    var lUserRole
            //}
            //var lUserInfo = 
            return aUserBusiness.SelectUserByRole(RoleName);
        }

        public UserInfo getUserByKey(int UserId)
        {
            return aUserBusiness.SelectByPrimaryId(UserId);
        }
    }
}
